#ifndef EXPORTPROGRESS_H
#define EXPORTPROGRESS_H

#include <QString>

/**
 * ExportProgress - 导出进度值对象
 *
 * Martin Fowler重构：Replace Data Clumps with Value Object
 * 将分散的导出进度数据（completedFiles, totalFiles, status）
 * 封装成一个不可变的值对象，提供清晰的业务逻辑接口
 */
class ExportProgress
{
public:
    // 构造函数
    ExportProgress(int completed = 0, int total = 0, const QString& status = "")
        : m_completedFiles(completed)
        , m_totalFiles(total)
        , m_status(status)
    {
    }

    // 不可变访问器
    int completedFiles() const { return m_completedFiles; }
    int totalFiles() const { return m_totalFiles; }
    QString status() const { return m_status; }

    // 业务逻辑方法
    bool isComplete() const {
        return m_totalFiles > 0 && m_completedFiles >= m_totalFiles;
    }

    bool isInProgress() const {
        return m_totalFiles > 0 && m_completedFiles < m_totalFiles;
    }

    bool isIdle() const {
        return m_totalFiles == 0;
    }

    double percentage() const {
        return m_totalFiles > 0 ? (double)m_completedFiles / m_totalFiles * 100.0 : 0.0;
    }

    // 状态工厂方法
    static ExportProgress idle() {
        return ExportProgress(0, 0, "");
    }

    static ExportProgress started(int totalFiles) {
        return ExportProgress(0, totalFiles, "准备导出...");
    }

    static ExportProgress inProgress(int completed, int total, const QString& status) {
        return ExportProgress(completed, total, status);
    }

    static ExportProgress completed(int totalFiles) {
        return ExportProgress(totalFiles, totalFiles, "导出完成");
    }

    // 创建新的进度状态（不可变性）
    ExportProgress withProgress(int completed, const QString& status = "") const {
        QString newStatus = status.isEmpty() ? m_status : status;
        return ExportProgress(completed, m_totalFiles, newStatus);
    }

    ExportProgress withStatus(const QString& status) const {
        return ExportProgress(m_completedFiles, m_totalFiles, status);
    }

    // 相等比较
    bool operator==(const ExportProgress& other) const {
        return m_completedFiles == other.m_completedFiles &&
               m_totalFiles == other.m_totalFiles &&
               m_status == other.m_status;
    }

    bool operator!=(const ExportProgress& other) const {
        return !(*this == other);
    }

private:
    int m_completedFiles;
    int m_totalFiles;
    QString m_status;
};

#endif // EXPORTPROGRESS_H